/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    bool isPalindrome(ListNode* head) {
        queue<int> prev;
        stack<int> ptr;
        ListNode* cur=head;
        while(cur){
            prev.push(cur->val);
            ptr.push(cur->val);
            cur=cur->next;
        }
        while(!prev.empty() && !ptr.empty()){
            if(ptr.top()!=prev.front()){
                return false;
            }
            prev.pop();
            ptr.pop();
        }
        return true;
    }
};